package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.ReviewComments;
import com.zygh.policeasset.service.ReviewCommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping({"/reviewComments"})
@Api(tags = {"审批意见管理"})
@RestController
public class ReviewCommentsController {

    @Autowired
    ReviewCommentsService reviewCommentsService;

    @RequestMapping(value = {"/"}, method = {RequestMethod.GET})
    @ApiOperation("获取列表")
    public Object findAll() {
        return reviewCommentsService.findAll();
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加")
    public Object add(@RequestBody ReviewComments reviewComments) {
        if (this.reviewCommentsService.add(reviewComments) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("更新")
    public Object update(@RequestBody ReviewComments reviewComments) {
        if (reviewCommentsService.update(reviewComments) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("更新错误");
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("删除")
    public CommonResult delete(@PathVariable Integer id) {

        if (reviewCommentsService.delete(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }
}